package com.timmy.google_play.holder.detail;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.timmy.google_play.R;
import com.timmy.google_play.base.BaseHolder;
import com.timmy.google_play.bean.ItemBean;
import com.timmy.google_play.conf.Constants;
import com.timmy.google_play.utils.UIUtils;
import com.timmy.google_play.views.RatioFrameLayout;
import com.timmy.google_play.views.flyinflyout.RandomLayout;

import java.util.List;

import butterknife.BindView;
import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by Timmy on 2016/12/14.
 */
public class DetailPicHolder extends BaseHolder<ItemBean> {
    @BindView(R.id.app_detail_pic_iv_container)
    LinearLayout mAppDetailPicIvContainer;

    @Override
    protected View initHolderVIew() {

        return View.inflate(UIUtils.getContext(), R.layout.item_detail_pic, null);
    }

    @Override
    protected void refreshHolderView(ItemBean data) {
        List<String> screenList = data.screen;


        for (int i = 0; i < screenList.size(); i++) {
            String url = screenList.get(i);

            ImageView iv = new ImageView(UIUtils.getContext());

            //创建RatioFrameLayout
            RatioFrameLayout layout = new RatioFrameLayout(UIUtils.getContext());

            //设置属性
            layout.setRelative(RatioFrameLayout.RELATIVE_WIDTH);
            layout.setPicRatio((float) 150 / 250);

            //放置到容器当中
            layout.addView(iv);

            Picasso.with(UIUtils.getContext()).load(Constants.URLS.IMAGEBASEURL + url).into(iv);

            //得到屏幕的宽度
            int screenWidth = UIUtils.getResources().getDisplayMetrics().widthPixels;
            screenWidth = screenWidth - UIUtils.dp2px(24);

            int width  = screenWidth / 3;
            int height = RandomLayout.LayoutParams.WRAP_CONTENT;

            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, height);

            if (i != 0) {
                params.leftMargin = UIUtils.dp2px(5);
            }
            mAppDetailPicIvContainer.addView(layout, params);
        }

    }
}
